<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>推荐人</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link href="/resources/css/base.css" rel="stylesheet" type="text/css" />
<link href="/resources/js/miniui/themes/default/miniui.css" rel="stylesheet" type="text/css" />
<script src="/resources/js/jquery-1.6.2.min.js" type="text/javascript"></script>
<script src="/resources/js/miniui/miniui.js" type="text/javascript"></script>
<script src="/resources/js/wbkDate.js" type="text/javascript"></script>
<script src="/resources/js/statusUtil.js" type="text/javascript"></script>
<style type="text/css">
#editWindow {
	top: 50px !important;
	left: 250px !important
}
</style>
</head>

<body>
	<div style="padding-top: 5px; padding-bottom: 5px; width: 95%;">
		<a class="mini-button" img="/resources/js/miniui/themes/icons/add.gif"
			onclick="load4add()">增加</a> <a class="mini-button"
			img="/resources/js/miniui/themes/icons/edit.gif" onclick="editRow()">修改</a>
		<a class="mini-button"
			img="/resources/js/miniui/themes/icons/remove.gif" onclick="delRow()">删除</a>
		<!-- <div style="float: right;">
			<span>用户手机号：</span><input type="text" id="register_user" /> 
			<span>推荐人手机号：</span><input type="text" id="recommend_user" /> 
			<input type="button" value="查找" onclick="search()" />
		</div> -->
	</div>

	<div id="mini-datagrid" class="mini-datagrid"
		style="width: 95%; height: 400px;" url="/app/refferee/list"
		pageSize="20" idField="id" allowResize="true">

		<div property="columns">
			<div type="indexcolumn">序号</div>
			<div type="checkcolumn">选择</div>
			<div field="userId">用户ID</div>
			<div field="invitedUserId">推荐人ID</div>
			<div field="createTime" >注册时间</div>
		</div>
	</div>


	<div id="editWindow" class="mini-window" title="推荐人"
		style="width: 350px;" showModal="true" allowResize="true"
		allowDrag="true">
		<div id="editform" class="form">
			<input class="mini-hidden" name="id" value="0" />
			<table style="width: 100%;">
				<tr>
					<td style="width: 30%; text-align: right;">注册人ID：</td>
					<td style="width: 70%; text-align: left;"><input name="userId"
						class="mini-textbox" maxLength=200 /></td>
				</tr>
				<tr>
					<td style="width: 30%; text-align: right;">推荐人ID：</td>
					<td style="width: 70%; text-align: left;"><input name="invitedUserId"
						class="mini-textbox" maxLength=200 /></td>
				</tr>
				<tr>
					<td
						style="text-align: center; padding-top: 5px; padding-right: 20px;"
						colspan="6"><a class="mini-button"
						img="/resources/js/miniui/themes/icons/save.gif"
						onclick="saveRow()">保存</a> <a class="mini-button"
						img="/resources/js/miniui/themes/icons/cancel.gif"
						onclick="cancelRow()">取消</a></td>
				</tr>

			</table>
		</div>
	</div>

</body>
<script type="text/javascript">
	mini.parse();
	var datagrid = mini.get("mini-datagrid");
	var editWindow = mini.get("editWindow");
	var form = new mini.Form("editform");
	var actionType = "insert";
	datagrid.load();

	function load4add() {
		actionType = "insert";
		editWindow.show();
		form.clear();
	}

	function saveRow() {
		var json = form.getData();
		console.log(json.id);
		if (json.id == 'undefined' || json.id == '') {
			json.id = 0;
		}
		console.log(json);
		$.ajax({
			url : "/app/refferee/" + actionType,
			data : json,
			type : "post",
			success : function(text) {
				editWindow.hide();
				datagrid.reload();
			},
			error : function(jqXHR, textStatus, errorThrown) {
				alert(jqXHR.responseText);
			}
		});

	}

	function cancelRow() {
		datagrid.reload();
		editWindow.hide();
	}

	function editRow() {

		var node = datagrid.getSelected();
		if (node) {
			actionType = "update";
			editWindow.show();
			form.clear();
			form.setData(node);
		} else {
			mini.alert("请选择一条!");
		}
	}

	function delRow() {

		var node = datagrid.getSelected();
		if (node) {
			mini.confirm("确定删除！", "提示", function(retCode) {
				console.log(retCode);
				if (retCode == 'ok') {
					// dosomething 删除
					$.ajax({
						url : "/app/refferee/delete",
						data : {
							id : node.id
						},
						type : "post",
						success : function(text) {
							editWindow.hide();
							datagrid.reload();
						},
						error : function(jqXHR, textStatus, errorThrown) {
							alert(jqXHR.responseText);
						}
					});

				}
			})
		} else {
			mini.alert("请选择一条!");
		}
	}

/* 	function search() {
		datagrid.load({
			registerUser : $('#register_user').val(),
			recommendUser : $('#recommend_user').val()
		});
	} */

</script>

</html>
